﻿using UnityEngine;
using System.Collections;

public class test : MonoBehaviour {

	// Use this for initialization
	public string wordWrap(GUIText guiText) 
	{
        string copy = guiText.text;
        string[] words = guiText.text.Split(' ');

        string result = "";

        Rect textArea = new Rect();



        for (int i = 0; i < words.Length; i++)
        {

            // set the gui text to the current string including new word

            guiText.text = (result + words[i] + " ");

            // measure it

            textArea = guiText.GetScreenRect();
            print(textArea);

            // if it didn't fit, put word onto next line, otherwise keep it
            print(textArea.width + textArea.x + " " + Camera.main.pixelWidth);
            if (textArea.width+textArea.x > Camera.main.pixelWidth)
            {
                print("I GET HERE");
                result += ("\n" + words[i] + " ");

            }

            else
            {

                result = guiText.text;

            }
        }
        return result;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
